<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>添加电缆2计划</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="./lib/layui-v2.6.3/css/layui.css" media="all">
</head>
<body>
<div class="layui-container" style="padding: 20px;">
    <form class="layui-form" id="addForm">

        <div class="layui-form-item">
            <label class="layui-form-label">项目编号</label>
            <div class="layui-input-block">
                <input type="text" name="projectNumber" required lay-verify="required" placeholder="请输入项目编号" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">项目名称</label>
            <div class="layui-input-block">
                <input type="text" name="projectName" required lay-verify="required" placeholder="请输入项目名称" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">电缆名称</label>
            <div class="layui-input-block">
                <input type="text" name="cableName" required lay-verify="required" placeholder="请输入电缆名称" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">电压等级</label>
            <div class="layui-input-block">
                <input type="text" name="voltageLevel" placeholder="请输入电压等级" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">电缆截面</label>
            <div class="layui-input-block">
                <input type="text" name="crossSection" placeholder="请输入电缆截面" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">预计抽取长度(m)</label>
            <div class="layui-input-block">
                <input type="number" name="lengthExpected" placeholder="请输入预计抽取长度" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">抽取日期</label>
            <div class="layui-input-block">
                <input type="date" name="dateExtraction" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                <select name="status" lay-verify="required">
                    <option value="">请选择状态</option>
                    <option value="0">未完成</option>
                    <option value="1">已完成</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="addSubmit">提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>

<script src="./lib/layui-v2.6.3/layui.js"></script>
<script>
    layui.use(['form', 'jquery', 'layer'], function () {
        var $ = layui.jquery,
            form = layui.form,
            layer = layui.layer;

        // 提交事件
        form.on('submit(addSubmit)', function (data) {
            $.ajax({
                url: '/plan/cable2/add',
                type: 'POST',
                contentType: 'application/json',
                data: JSON.stringify(data.field),
                success: function (res) {
                    if (res.code === 0) {
                        layer.msg('添加成功');
                        parent.layer.close(parent.layer.getFrameIndex(window.name)); // 关闭弹窗
                        parent.location.reload(); // 刷新父页面
                    } else {
                        layer.msg('添加失败：' + res.msg);
                    }
                },
                error: function () {
                    layer.msg('网络异常，请稍后再试');
                }
            });
            return false;
        });
    });
</script>
</body>
</html>
